<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%
    // 检查用户是否登录
    Integer userId = (Integer) session.getAttribute("userId");
    if (userId == null) {
        response.sendRedirect("login.jsp");
        return;
    }
    
    // 获取用户信息
    String username = (String) session.getAttribute("username");
    String phone = (String) session.getAttribute("phone");
    String email = (String) session.getAttribute("email");
%>

<!DOCTYPE html>
<html>
<head>
    <title>个人中心 - 淘乐乐商城</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <style>
        .main-content {
            max-width: 1200px;
            margin: 20px auto;
            padding: 0 15px;
            display: flex;
            gap: 20px;
        }
        
        .sidebar {
            width: 250px;
            background: white;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
            padding: 20px;
        }
        
        .sidebar-menu {
            list-style: none;
            padding: 0;
            margin: 0;
        }
        
        .sidebar-menu li {
            margin-bottom: 10px;
        }
        
        .sidebar-menu a {
            display: flex;
            align-items: center;
            padding: 10px;
            color: #666;
            text-decoration: none;
            border-radius: 4px;
            transition: background-color 0.3s;
        }
        
        .sidebar-menu a:hover {
            background-color: #f5f5f5;
        }
        
        .sidebar-menu a.active {
            background-color: #ff4d4f;
            color: white;
        }
        
        .sidebar-menu i {
            margin-right: 10px;
            width: 20px;
            text-align: center;
        }
        
        .content {
            flex: 1;
            background: white;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
            padding: 20px;
        }
        
        .section-title {
            font-size: 20px;
            font-weight: bold;
            margin-bottom: 20px;
            padding-bottom: 10px;
            border-bottom: 1px solid #eee;
        }
        
        .form-group {
            margin-bottom: 20px;
        }
        
        .form-group label {
            display: block;
            margin-bottom: 5px;
            color: #666;
        }
        
        .form-group input {
            width: 100%;
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
        }
        
        .form-group input:focus {
            border-color: #ff4d4f;
            outline: none;
        }
        
        .save-button {
            background-color: #ff4d4f;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 4px;
            cursor: pointer;
            transition: background-color 0.3s;
        }
        
        .save-button:hover {
            background-color: #ff6b6b;
        }
    </style>
</head>
<body>
    <%@ include file="header.jsp" %>
    
    <div class="main-content">
        <div class="sidebar">
            <ul class="sidebar-menu">
                <li>
                    <a href="profile.jsp" class="active">
                        <i class="fas fa-user"></i>
                        个人信息
                    </a>
                </li>
                <li>
                    <a href="my-orders.jsp">
                        <i class="fas fa-shopping-bag"></i>
                        我的订单
                    </a>
                </li>
                <li>
                    <a href="address.jsp">
                        <i class="fas fa-map-marker-alt"></i>
                        收货地址
                    </a>
                </li>
                <li>
                    <a href="favorites.jsp">
                        <i class="fas fa-heart"></i>
                        我的收藏
                    </a>
                </li>
                <li>
                    <a href="account-settings.jsp">
                        <i class="fas fa-cog"></i>
                        账号设置
                    </a>
                </li>
            </ul>
        </div>
        
        <div class="content">
            <h2 class="section-title">个人信息</h2>
            
            <form action="updateProfile" method="post" id="profileForm">
                <div class="form-group">
                    <label for="username">用户名</label>
                    <input type="text" id="username" name="username" value="${username}" required>
                </div>
                
                <div class="form-group">
                    <label for="phone">手机号码</label>
                    <input type="tel" id="phone" name="phone" value="${phone}" pattern="[0-9]{11}" required>
                </div>
                
                <div class="form-group">
                    <label for="email">电子邮箱</label>
                    <input type="email" id="email" name="email" value="${email}" required>
                </div>
                
                <button type="submit" class="save-button">保存修改</button>
            </form>
        </div>
    </div>
    
    <%@ include file="footer.jsp" %>
    
    <script>
        document.getElementById('profileForm').addEventListener('submit', function(e) {
            e.preventDefault();
            
            // 收集表单数据
            const formData = new FormData(this);
            
            // 发送AJAX请求
            fetch('updateProfile', {
                method: 'POST',
                body: new URLSearchParams(formData)
            })
            .then(response => response.json())
            .then(data => {
                if (data.success) {
                    alert('个人信息更新成功！');
                } else {
                    alert(data.message || '更新失败，请重试');
                }
            })
            .catch(error => {
                console.error('Error:', error);
                alert('更��失败，请重试');
            });
        });
    </script>
</body>
</html> 